<?php

namespace App\Http\Requests\Admin\Customer\Advert;

use App\Http\Requests\ApiRequest;
use App\Http\Requests\Concerns\AdvertRule;

/**
 * @property string advert_type_id
 * @property string name
 * @property string content_key
 * @property string play_second
 * @property array device_account_ids
 */
class AdvertUpdateRequest extends ApiRequest
{
    use AdvertRule;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $content_key_rule = is_file($this->content_key) ? 'file' : 'string';
        return [
            'advert_type_id'       => 'sometimes|required|int|in:1,2',
            'name'                 => 'sometimes|required|string|max:'.self::MAX_STRING,
            'content_key'          => 'sometimes|required|' . $content_key_rule,
            'play_second'          => 'sometimes|required|int|max:'.self::MAX_INT,
            'device_account_ids'   => 'sometimes|required|array',
            'device_account_ids.*' => 'sometimes|required|int',
        ] + $this->redirectableRules();
    }
}
